-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PMD: LiteralsFirstInComparisons for compareTo* and contentEquals #366
PMD: LiteralsFirstInComparisons for compareTo* and contentEquals #366
Conversation
src/main/java/org/openrewrite/staticanalysis/EqualsAvoidsNullVisitor.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/java/org/openrewrite/staticanalysis/ChainStringBuilderAppendCalls.java
- lines 35-36
if (!(m.getSelect() instanceof J.Literal) | ||
&& m.getArguments().get(0) instanceof J.Literal | ||
&& (EQUALS.matches(m) | ||
|| !style.getIgnoreEqualsIgnoreCase() | ||
&& EQUALS_IGNORE_CASE.matches(m) | ||
|| COMPARE_TO.matches(m) | ||
|| COMPARE_TO_IGNORE_CASE.matches(m) | ||
|| CONTENT_EQUALS.matches(m))) { | ||
final Object parent = getCursor().getParentTreeCursor().getValue(); | ||
if (parent instanceof J.Binary) { | ||
J.Binary binary = (J.Binary) parent; | ||
if (binary.getOperator() == J.Binary.Type.And && binary.getLeft() instanceof J.Binary) { | ||
J.Binary potentialNullCheck = (J.Binary) binary.getLeft(); | ||
if ((isNullLiteral(potentialNullCheck.getLeft()) && matchesSelect(potentialNullCheck.getRight(), m.getSelect())) || | ||
(isNullLiteral(potentialNullCheck.getRight()) && matchesSelect(potentialNullCheck.getLeft(), m.getSelect()))) { | ||
final J.Binary binary = (J.Binary) parent; | ||
if (binary.getLeft() instanceof J.Binary | ||
&& binary.getOperator() == J.Binary.Type.And) { | ||
final J.Binary potentialNullCheck = (J.Binary) binary.getLeft(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!(m.getSelect() instanceof J.Literal) | |
&& m.getArguments().get(0) instanceof J.Literal | |
&& (EQUALS.matches(m) | |
|| !style.getIgnoreEqualsIgnoreCase() | |
&& EQUALS_IGNORE_CASE.matches(m) | |
|| COMPARE_TO.matches(m) | |
|| COMPARE_TO_IGNORE_CASE.matches(m) | |
|| CONTENT_EQUALS.matches(m))) { | |
final Object parent = getCursor().getParentTreeCursor().getValue(); | |
if (parent instanceof J.Binary) { | |
J.Binary binary = (J.Binary) parent; | |
if (binary.getOperator() == J.Binary.Type.And && binary.getLeft() instanceof J.Binary) { | |
J.Binary potentialNullCheck = (J.Binary) binary.getLeft(); | |
if ((isNullLiteral(potentialNullCheck.getLeft()) && matchesSelect(potentialNullCheck.getRight(), m.getSelect())) || | |
(isNullLiteral(potentialNullCheck.getRight()) && matchesSelect(potentialNullCheck.getLeft(), m.getSelect()))) { | |
final J.Binary binary = (J.Binary) parent; | |
if (binary.getLeft() instanceof J.Binary | |
&& binary.getOperator() == J.Binary.Type.And) { | |
final J.Binary potentialNullCheck = (J.Binary) binary.getLeft(); | |
if (!(m.getSelect() instanceof J.Literal) && | |
m.getArguments().get(0) instanceof J.Literal && | |
(EQUALS.matches(m) || | |
!style.getIgnoreEqualsIgnoreCase() && | |
EQUALS_IGNORE_CASE.matches(m) || | |
COMPARE_TO.matches(m) || | |
COMPARE_TO_IGNORE_CASE.matches(m) || | |
CONTENT_EQUALS.matches(m))) { | |
if (binary.getLeft() instanceof J.Binary && | |
binary.getOperator() == J.Binary.Type.And) { | |
if (isNullLiteral(potentialNullCheck.getLeft()) && | |
matchesSelect(potentialNullCheck.getRight(), m.getSelect()) || | |
isNullLiteral(potentialNullCheck.getRight()) && | |
matchesSelect(potentialNullCheck.getLeft(), m.getSelect())) { |
src/test/java/org/openrewrite/staticanalysis/EqualsAvoidsNullTest.java
Outdated
Show resolved
Hide resolved
…est.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
So, will the GitHub Action apply the recipes by Moderna, or how is the engine executed? The automation aspect is not yet completed in my team. We have just explored this tool but haven't managed to fully automate the processes yet. However, it has still been helpful. |
Please feel free to reuse a PR that's already opened, as opposed to closing and opening a new one. We squash merge, so there's no need to keep a clean history. I'd rather just have a single PR that we can discuss everything on including what we've learned since it was opened, than have that spread across various PRs some of which never get merged. |
We've documented our flow on the Moderne blog: https://www.moderne.ai/blog/stop-breaking-ci-annotate-prs-with-openrewrite-recipe-fixes-as-quality-gate I hope that helps you integrate recipe runs into your workflows there. Do note that Moderne would allow you to run these at scale, as opposed to getting a performance penalty on each CI run. |
LiteralsFirstInComparisons
forcompareTo*
andcontentEquals
#362